import { ElMessage } from "element-plus";
import { useUserState } from "@/store/user";
import router from "@/router";

export function logOut(before?: (() => void) | null, after?: () => void) {
  const userStore = useUserState();
  // 清除本地token
  before && before();
  localStorage.removeItem("token");
  // 把动态路由清除
  userStore.menus.forEach((item) => {
    router.removeRoute(item.name);
  });
  // 清除pinia仓库的数据
  userStore.username = "";
  userStore.menus = [];
  router.push("/login");
  after && after();
}
